<!--设置个性化指标-->
<template>
  <div class="wrapper-container">
    <div class="search-container">
      <div class="filter-button">
        <el-radio-group style="margin-right: 10px" v-model="radio4" size="mini">
          <el-radio-button style="padding-right: 10px" label="问答题"
            >问答题</el-radio-button
          >
          <el-radio-button label="选择题">选择题</el-radio-button>
        </el-radio-group>
      </div>
    </div>
    <div v-if="radio4 == '选择题'">
      <el-form
        ref="form"
        v-for="(item, index) in form"
        class="my-form"
        :key="index"
      >
        <el-row class="single-row">
          <el-col :span="24">
            <el-row class="item-row">
              <el-col class="name-col" :span="6"> 题干 </el-col>

              <el-col class="content-col" :span="18">
                <el-input
                  v-model="item.question"
                  style="width: 800px; margin-left: 30px"
                  size="small"
                ></el-input>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row class="single-row">
          <el-col :span="24">
            <el-row class="item-row">
              <el-col class="name-col" style="height: 200px" :span="6">
                选项
              </el-col>
              <el-col class="content-col" :span="18">
                <div
                  style="margin: 5px 0"
                  v-for="(item1, index1) in formList"
                  :key="index1"
                >
                  {{ item1.toUpperCase() }}：<el-input
                    v-model="item['option' + item1]"
                    style="width: 800px; margin-left: 15px"
                    size="small"
                  ></el-input>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-form v-else ref="form" class="my-form">
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 题干 </el-col>
            <el-col :span="18">
              <el-row class="item-row2">
                <el-col
                  v-for="(item, index) in form2"
                  :key="index"
                  class="content-col"
                  :span="24"
                >
                  <span>
                    <el-input
                      v-model="item.question"
                      style="width: 800px"
                      size="small"
                    ></el-input
                  ></span>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>

    <div class="search-container">
      <ButtonItem
        :name="'增加题干'"
        @click="addQuestion"
        :link="''"
        :icon="'el-icon-circle-plus-outline'"
        :buttonColor="'yellow'"
      ></ButtonItem>
    </div>
    <div style="width: 100%; display: flex; justify-content: center">
      <ButtonItem
        @click="saveClick"
        :name="'保存'"
        :link="''"
        :icon="''"
        :buttonColor="'yellow'"
      ></ButtonItem>
    </div>
  </div>
</template>

<script>
import ButtonItem from "../../../components/ButtonItem.vue";
import // inserts,
// pjindividualizedqatinserts,
// pjindividualizedqatselectByTorId,
// selectByTorId
"@/api/teacher/admin";

import {
  inserts,
  pjindividualizedqatinserts,
  pjindividualizedqatselectByTorId,
  selectByTorId
} from "../../../api/teacher/admin";

export default {
  components: {
    ButtonItem
  },
  data() {
    return {
      quers: "",
      form: [
        {
          evalid: "2",
          individualizedid: "1",
          optiona: "很好",
          optionb: "好",
          optionc: "不好",
          optiond: "很不好",
          question: "你觉得我讲的课怎么样啊"
        }
      ],
      formList: ["a", "b", "c", "d"],
      teacherid: this.$route.query.teacherid,
      objectid: this.$route.query.evalprojectid,
      evalid: this.$route.query.evalactorid,
      form2: [
        {
          teacherid: "this.$route.query.teacherid",
          objectid: this.$route.query.evalprojectid,
          evalid: this.$route.query.evalactorid,
          individualizedid: "1",
          question: "你觉得我讲的课怎么样哦"
        }
      ],
      radio4: this.$route.query.radio4 ? this.$route.query.radio4 : "选择题"
    };
  },
  mounted() {
    this.selectByTorId1();
    this.pjindividualizedqatselectByTorId1();
  },
  methods: {
    //查询问答题
    pjindividualizedqatselectByTorId1() {
      return new Promise(() => {
        pjindividualizedqatselectByTorId({
          id: this.$route.query.evalactorid,
          tid: this.$route.query.teacherid,
          objectid: this.$route.query.evalprojectid
        }).then(res => {
          this.form2 = res.data.data;
        });
      });
    },

    //查询选择题
    selectByTorId1() {
      return new Promise(() => {
        selectByTorId({
          id: this.$route.query.evalactorid,
          tid: this.$route.query.teacherid,
          objectid: this.$route.query.evalprojectid
        }).then(res => {
          this.form = res.data.data;
        });
      });
    },
    saveClick() {
      if (this.radio4 === "问答题") {
        this.pjindividualizedqatinserts1();
      } else if (this.radio4 === "选择题") {
        this.inserts1();
      }
    },
    //添加保存问答题
    pjindividualizedqatinserts1() {
      return new Promise(() => {
        pjindividualizedqatinserts(this.form2).then(res => {
          if (res.data.code == 200) {
            this.$router.push("/teacher/eligible/eligibleCourse");
          }
        });
      });
    },
    //修改保存选择题
    inserts1() {
      return new Promise(() => {
        inserts(this.form).then(res => {
          if (res.data.code == 200) {
            this.$router.push("/teacher/eligible/eligibleCourse");
          }
        });
      });
    },

    addQuestion() {
      if (this.radio4 == "选择题") {
        //   evalactorid: evalactorid,
        //   teacherid: teacherid,
        //   evalprojectid: evalprojectid
        this.form.push({
          teacherid: this.teacherid,
          objectid: this.objectid,
          evalid: this.evalid,
          individualizedid: "",
          optiona: "",
          optionb: "",
          optionc: "",
          optiond: "",
          question: ""
        });
        console.log("点击添加选择题", this.form);
      } else {
        this.form2.push({
          teacherid: this.teacherid,
          objectid: this.objectid,
          evalid: this.evalid,
          question: "",
          individualizedid: ""
        });
      }
    }
  },
  watch: {
    radio4(val) {
      //   var _this = this;
      //   this.tableChangeFlag = true;
      //   window.setTimeout(() => {
      //     _this.tableChangeFlag = false;
      //     this.mergeRow();
      //   }, 500);
    }
  },

  computed: {}
};
</script>
<style lang="less" scoped>
.search-container {
  justify-content: flex-start !important;
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../../styles/special.less";

.item-row .el-col {
  display: flex;
  align-items: center;
  min-height: 60px;
  border-right: none !important;
}
.item-row .el-col:not(:first-child) {
  border-left: 1px solid rgba(0, 76, 167, 0.39);
}
.item-row2 {
  width: 100%;
}
.item-row2 .el-col:not(:first-child) {
  border-top: 1px solid rgba(0, 76, 167, 0.39);
}
.item-row2 .el-col:not(:first-child) {
  border-left: none !important;
}
.single-row .el-col:not(:last-child) {
  border-right: 1px solid rgba(0, 76, 167, 0.39);
}
.my-form .single-row:not(:last-child) {
  border-bottom: 1px solid rgba(0, 76, 167, 0.39);
}
.name-col {
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #004ca7;
  background: rgba(77, 129, 192, 0.1);
}
.content-col {
  padding-top: 10px;
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: self-start !important;
  justify-content: center !important;
  padding-left: 30px;
  color: #004ca7;
}
.wrapper-container {
  .my-form {
    width: 1737px;
    border: 1px solid rgba(0, 76, 167, 0.8);
    margin: 25px auto 19px;
  }
  .button-group {
    padding-top: 20px;
    width: 915px;
    margin: 0 auto;
    text-align: center;
    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;
      &:nth-child(1) {
        color: #f3b815;
        border: 1px solid #f3b815;
        background: #fff6ef;
        margin: 0 40px;
      }
    }
  }
}
.filter-button {
  display: flex;
  justify-content: start;
}
.filter-button::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid rgb(245, 134, 106);
  color: rgb(245, 134, 106);
  background-color: rgb(254, 237, 226);
}
.filter-button::v-deep
  .el-radio-button__orig-radio:checked
  + .el-radio-button__inner {
  border: 1px solid rgb(245, 134, 106);
  color: white;
  background-color: rgb(245, 134, 106);
}
.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}
.table-container {
  margin-top: 30px;

  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
